/**
 * 
 */
package com.wodsy.phoenix.dataservice.cms.service.impl;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.container.Main;
import com.wodsy.phoenix.datadao.base.IBaseDao;
import com.wodsy.phoenix.datadao.cms.dao.CmsHomePageBannerDao;
import com.wodsy.phoenix.dataobject.base.Pager;
import com.wodsy.phoenix.dataobject.cms.constants.HomePageObjectType;
import com.wodsy.phoenix.dataobject.cms.model.IdxAdPic;
import com.wodsy.phoenix.dataobject.cms.vo.IdxAdPicResp;
import com.wodsy.phoenix.dataservice.base.AbstractBaseService;
import com.wodsy.phoenix.dataservice.cms.aop.AfterOperation;
import com.wodsy.phoenix.dataservice.cms.service.CmsHomePageBannerService;

/**
 * @author bryan
 *
 */
@Service(interfaceClass = CmsHomePageBannerService.class, interfaceName = "com.wodsy.phoenix.dataservice.cms.service.CmsHomePageBannerService")
public class CmsHomePageBannerServiceImpl extends AbstractBaseService<IdxAdPic,Integer> implements CmsHomePageBannerService{

	@Autowired
	private CmsHomePageBannerDao cmsHomePageDao;
	
	@Override
	protected IBaseDao<IdxAdPic, Integer> getIBaseDao() {
		return cmsHomePageDao;
	}
	
	@Transactional(readOnly= true)
	@Override
	public List<IdxAdPicResp> getOnlinePicBanner() {
		/*List<IdxAdPic> list = cmsHomePageDao.getOnlinePicBanner();
		List<IdxAdPicResp> respList = new ArrayList<IdxAdPicResp>();
		IdxAdPicResp tbapr = null;
		for (IdxAdPic tbIdxAdPic : list) {
			tbapr = new IdxAdPicResp();
			try {
				BeanUtils.copyProperties(tbapr, tbIdxAdPic);
				respList.add(tbapr);
			} catch (IllegalAccessException | InvocationTargetException e) {
				logger.error("object copy error!", e);
			}
		}
		return respList;*/
		List<IdxAdPic> list = cmsHomePageDao.getOnlinePicBanner();
		List<IdxAdPicResp> respList = new ArrayList<IdxAdPicResp>();
		IdxAdPicResp idxAdPicResp = null;
		for (IdxAdPic idxAdPicTmp : list) {
			idxAdPicResp = new IdxAdPicResp();
			try {
				BeanUtils.copyProperties(idxAdPicResp, idxAdPicTmp);
				respList.add(idxAdPicResp);
			} catch (IllegalAccessException | InvocationTargetException e) {
				logger.error("object copy error!", e);
			}
		}
		return respList;
	}
	@Transactional(readOnly= true)
	@Override
	public Pager<IdxAdPic> searchBannerPicByOrder(Pager<IdxAdPic> adPic,IdxAdPic picreq){
		Pager<IdxAdPic> pager = cmsHomePageDao.searchBannerPicByOrder(adPic,picreq);
		return pager;
	}
	@Transactional(readOnly= false)
	//@AfterManuallyOperation(objectId="#bannerId",objectStatus="#status",objectType=HomePageObjectType.NEWGOODSRECOMMENDED)
	@Override
	public Integer updateBannerPicStatus(int bannerId,
			int status) {
		return cmsHomePageDao.updateBannerPicStatus(bannerId, status);
	}
	
	@Transactional(readOnly= false)
	//@AfterManuallyOperation(objectId="#bannerIds",objectStatus="#status",objectType=HomePageObjectType.NEWGOODSRECOMMENDED)
	@Override
	public Integer updateBannerPicStatus(Integer[] bannerIds, int status) {
		return cmsHomePageDao.updateBannerPicStatus(bannerIds, status);
	}
	
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#banner.id",objectType=HomePageObjectType.NEWGOODSRECOMMENDED,
	offlineTime="#banner.offlineTime",onlineTime="#banner.onlineTime" )
	@Override
	public Integer addBannerRecommended(IdxAdPic banner) {
		Integer bannerId = cmsHomePageDao.addBannerRecommended(banner);
		
		return bannerId;

	}
	@Transactional(readOnly=false)
	@AfterOperation(objectId="#banner.id",objectType=HomePageObjectType.NEWGOODSRECOMMENDED,
	offlineTime="#banner.offlineTime",onlineTime="#banner.onlineTime" )
	@Override
	public void updateBannerRecommended(IdxAdPic banner) {
		cmsHomePageDao.updateBannerRecommended(banner);
	}

	public static void main(String[] args) {
		Main.main(args);
	}

}
